SRC_DIR		= src/
TST_DIR		= test/
DOC_DIR		= doc/
DOXYGEN		=/Applications/Doxygen.app/Contents/Resources/doxygen

# Default
all: 
	make -C $(SRC_DIR)

plc:
	make -C $(SRC_DIR) clean
	make -C $(SRC_DIR)

# Run the Tests for pl compiler
plc_tests:	plc
	@echo;\
	echo "==Test 1: No output is expected on Succesfull tests ==";\
	echo "";\
	echo "==Test 1a: Test All (pl interperator code) =="
	$(SRC_DIR)plc -i test_all.inter -o test_all.asm $(TST_DIR)test_all.pl 
	diff test_all.asm $(TST_DIR)test_all.asm
	
	@echo;\
	echo "==Test 1b: Test All (MIPS interperator code) =="
	$(SRC_DIR)plc -m -i test_all_MIPS.inter -o test_all.mips $(TST_DIR)test_all.pl 
	diff test_all.mips $(TST_DIR)test_all.mips

	@echo;\
	echo "==Test 1c: Test All (compare intermidiate output) =="
	diff test_all.inter test_all_MIPS.inter

	@echo;\
	echo "==Test 1d: Test All (compare pl interpereter & SPIM output) =="
	(echo 1;echo 2;echo 3) | $(TST_DIR)pl-interpreter $(TST_DIR)test_all.asm | grep Output > test_all.output
	(echo 1;echo 2;echo 3) | spim -file $(TST_DIR)test_all.mips | grep Output > test_all_MIPS.output
	diff -w test_all.output test_all_MIPS.output

	@echo;\
	echo;\
	echo "==Test 2: Output is expected, reporting error lines  ==";\
	echo "make will fail after this test";\
	echo "";\
	echo "==Test 2a: Test Error Reports =="
	echo "Expected Results:";\
	echo "Parser error :: Line 35 :: Expecting a Symbol 'EQUAL' , but read a Symbol, 'MINUS'";\
	echo "Parser error :: Line 38 :: a is previously defined in the block";\
	echo "Parser error :: Line 39 :: Expected a Variable Definition";\
	echo "Parser error :: Line 42 :: Not defined as a procedure, 'a'";\
	echo "Parser error :: Line 46 :: Undefined 'foo' ";\
	echo "Scanner error :: Line 52 :: Invalid character '-', expecting '='";\
	echo "Parser error :: Line 52 :: Expecting a Symbol 'ASSIGN' , but read a Symbol, 'SEMI_COLON'";\
	echo "Scanner error :: Line 55 :: Ill formed number '5a', extra character(s) after number";\
	echo "";\
	$(SRC_DIR)plc -o error.asm $(TST_DIR)error.pl

	

# Debug
debug:
	make -C $(SRC_DIR) clean 
	make -C $(SRC_DIR) MACRO=-DDEBUG


# Clean
clean:
	rm -f test_all* error*
	make -C $(SRC_DIR) clean


# Make documentation with Doxygen
# Output: HTML and PDF
docs: 
	$(DOXYGEN)
	# make -C $(DOC_DIR)latex pdf
